Using string[] as a Dictionary key e.g. Dictionary<string[], StringBuilder>

Posted by Nick Allen - Tungle139 on Stack Overflow See other posts from Stack Overflow or by Nick Allen - Tungle139
Published on 2010-03-30T17:02:10Z Indexed on 2010/03/30 18:03 UTC
Read the original article Hit count: 418

Filed under:
|

The structure I am trying to achieve is a composite Dictionary key which is item name and item displayname and the Dictionary value being the combination of n strings

So I came up with

var pages = new Dictionary<string[], StringBuilder>()
{
    { new string[] { "food-and-drink", "Food & Drink" }, new StringBuilder() },
    { new string[] { "activities-and-entertainment", "Activities & Entertainment" }, new StringBuilder() }
};

foreach (var obj in my collection)
{
    switch (obj.Page)
    {
        case "Food":
        case "Drink":
            pages["KEY"].Append("obj.PageValue");
            break;
        ...
    }
}

The part I am having trouble with is accessing the Dictionary Key pages["KEY"]

How do I target the Dictionary Key whose value at [0] == some value?

Hope that makes sense

© Stack Overflow or respective owner

Related posts about generics

Related posts about data-structures